<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    class Dog {
        speak() {
            console.log('dog')
        }
    }

    class Cat {
        speak() {
            console.log('cat')
        }
    }

    class Pet {
        whatDoesMyPetSay() {
            // 宠物是狗
            const pet = new Dog()
            pet.speak()
        }
    }

    new Pet().whatDoesMyPetSay()

    class Pet2 {
        whatDoesMyPetSay(pet) {
            new pet().speak()
        }
    }

</script>
</body>
</html>
